package servlet;

import util.*;

import java.io.*;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Alter extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //获取客户端请求的参数，并进行判断。

        request.setCharacterEncoding("utf-8");
        String id=request.getParameter("id").trim();//取得用户名参数
        String name=request.getParameter("name").trim();
        String sex=request.getParameter("sex").trim();
        String birthday=request.getParameter("birth").trim();
        String education=request.getParameter("degree").trim();
        String native_place=request.getParameter("origin").trim();
        String place=request.getParameter("address").trim();
        String phone=request.getParameter("tel").trim();
        String work_age=request.getParameter("wyear").trim();
        String base_pay=request.getParameter("wage").trim();

        HttpSession session = request.getSession();
        session.setAttribute("id", id);
        session.setAttribute("name", name);
        session.setAttribute("sex", sex);
        session.setAttribute("birth", birthday);
        session.setAttribute("degree", education);
        session.setAttribute("origin", native_place);
        session.setAttribute("address", place);
        session.setAttribute("tel", phone);
        session.setAttribute("wyear", work_age);
        session.setAttribute("wage", base_pay);

//        try{
//            DButil dButil = new DButil();
//            Connection con = dButil.getConnection();
//
//           String sql = "update staff set name=?,sex=?,birth=?,degree=?,origin=?,address=?,tel=?,wyear=?,wage=? where  id='" + id + "'";
//
//            PreparedStatement ps = con.prepareStatement(sql);
//            ps.setString(1, name);
//            ps.setString(2, sex);
//            ps.setString(3, birthday);
//            ps.setString(4, education);
//            ps.setString(5, native_place);
//            ps.setString(6, place);
//            ps.setString(7, phone);
//            ps.setDouble(8, work_age);
//            ps.setDouble(9, base_pay);
//            if (ps.executeUpdate() != 0){
//                RequestDispatcher dispatcher =
//                        request.getRequestDispatcher("select.jsp");//转发
//                dispatcher.forward(request, response);
//            }
//            else
//            {
//                RequestDispatcher dispatcher=
//                        request.getRequestDispatcher("index.jsp");//转发
//                dispatcher.forward(request,response);
//
//            }
//        }catch(Exception e){
//            e.printStackTrace();
//
//        }
        RequestDispatcher dispatcher=
                request.getRequestDispatcher("update.jsp");//转发
        dispatcher.forward(request,response);

    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
